package com.xayy.health.mgt.model;

import cn.kawins.base.utils.CollUtil;
import cn.kawins.base.utils.StringUtil;
import cn.kawins.mybatis.base.BaseModel;
import cn.kawins.mybatis.util.SnowflakeId;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import java.util.Arrays;
import java.util.List;

/**
 * 评估模型
 *
 * @author Nie
 * @version V1.0
 * @date 2023/5/25 15:48
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "HEALTH.assess_parma")
@EqualsAndHashCode(callSuper = true)
public class AssessParma extends BaseModel<Long> {

    @Id
    @Column(name = "id")
    @KeySql(genId = SnowflakeId.class)
    private Long id;

    @Column(name = "sat_id")
    @ApiModelProperty(value = "卫星id")
    private Long satId;

    @Column(name = "system_id")
    @ApiModelProperty(value = "分系统id")
    private Long systemId;

    @Column(name = "component_id")
    @ApiModelProperty(value = "部件id")
    private Long componentId;

    @Column(name = "assess_name")
    @ApiModelProperty(value = "评估模型名称")
    private String assessName;

    @Column(name = "assess_code")
    @NotBlank(message = "参数不能为空")
    @ApiModelProperty(value = "评估模型名称")
    private String assessCode;

    @Column(name = "param")
    @ApiModelProperty(value = "参数code", hidden = true)
    private String param;

    @Column(name = "correlate_code")
    @ApiModelProperty(value = "相关节点code", hidden = true)
    private String correlateCode;

    @Column(name = "visitor")
    @ApiModelProperty(value = "计算脚本")
    private String visitor;

    @Column(name = "default_calculate")
    @ApiModelProperty(value = "是否默认计算模型，单节点只能有一个默认模型")
    private Boolean defaultCalculate;

    @Transient
    @ApiModelProperty(value = "参数code集合")
    private List<String> paramList;

    @Transient
    @ApiModelProperty(value = "相关节点code集合")
    private List<String> correlateCodeList;

    public void setParam(String param) {
        this.param = param;
        if (StringUtil.isNotBlank(param)) {
            this.paramList = Arrays.asList(param.split(","));
        }
    }

    public void setParamList(List<String> paramList) {
        this.paramList = paramList;
        if (CollUtil.isNotEmpty(paramList)) {
            this.param = CollUtil.join(paramList, ",");
        }
    }

    public void setCorrelateCode(String correlateCode) {
        this.correlateCode = correlateCode;
        if (StringUtil.isNotBlank(correlateCode)) {
            this.correlateCodeList = Arrays.asList(correlateCode.split(","));
        }
    }

    public void setCorrelateCodeList(List<String> correlateCodeList) {
        this.correlateCodeList = correlateCodeList;
        if (CollUtil.isNotEmpty(correlateCodeList)) {
            this.correlateCode = CollUtil.join(correlateCodeList, ",");
        }
    }

    @Override
    public Long idValue() {
        return id;
    }
}
